﻿@using ST = EmoneyWeiXinCommon.StringTools;
@{
    ViewBag.Title = "后台图文素材列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="@Url.Content("~/Scripts/jsrender-min.js")"></script>
<script type="text/x-jsrender" id="temp1">
    <tr>
    <td><input type='checkbox'  onclick='selectAItem(this)' class='chks' mediaId='{{:media_id}}'/></td>
    <td>{{:media_id}}</td>
    <td>{{:allTitle}}</td>
    <td>{{:update_time}}</td>
    </tr>
</script>

<script type="text/javascript">
    var weixinid = "8";
    var pageIndex = 1;
    var pageSize = 20;
    var pageCount = 1;
    var totalCount = 0;
    var selMediaId = "";
    function createMemu() {
        $.ajax({
            type: "get",
            url: "@ST.GetTrendsFile("BaseConfiguration/WeixinUserMemu")" + "?random=" + Math.random(),
            async: true,
            data: { weixinid: "@ViewBag.weixinid" },
            dataType: "html",
            success: function (result) {
                $(".manage_top_ul").html(result);
                $(".manage_top_ul li").click(function () {
                    $(".manage_top_ul li").removeClass("manage_top_A");
                    $(this).addClass("manage_top_A");
                    $("#btnyxz").html("");
                    getContentMemu();
                })

                getContentMemu();
            }
        });
    }

    function getContentMemu() {
        $(".manage_top_ul .manage_top_A").each(function () {
            weixinid = $(this).attr("typeid");
        })
        if (weixinid > 1) {
            bindDrpList("@ST.GetTrendsFile("WXUser/QueryUserGroupList")", "spGroupID", "groupid", "id", "name", function () { });
        }
    }

    function bindDrpList(url, spid, id, value, name, fn) {
        $.ajax({
            url: url,
            type: "POST",
            async: true,
            data: { weixinid: weixinid },
            beforeSend: function () {
                //showLoading();
            },
            complete: function () {
                // hiddenLoading();
            },
            success: function (data) {
                datatype = eval(data);
                if (datatype) {
                    $("#" + spid).html("");
                    var d = datatype;
                    var html = '<select  id="' + id + '" ><option value="-1">全部</option>';
                    for (var i = 0; i < d.length; i++) {
                        html += ' <option value="' + d[i][value] + '">' + d[i][name] + '</option>';
                    }
                    html += '</select>';
                    $("#" + spid).append(html);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(errorThrown);
            }
        });
    }

    $(document).ready(function () {
        createMemu();
        gotoPage();
    });
    var ajaxdata = {};
    function gotoPage() {
        ajaxdata["pindex"] = pageIndex;
        ajaxdata["psize"] = pageSize;
        ajaxdata["weixinid"] = weixinid;
        $.ajax({
            url: "@ST.GetTrendsFile("Report/GetHtTwSucaiList")",
            type: "POST",
            async: true,
            dataType: 'json',
            data: ajaxdata,
            beforeSend: function () {
                //showLoading();
            },
            complete: function () {
                //iddenLoading();
            },
            success: function (r) {
                totalCount = r.total;
                var data = r.list;
                if (data != "" && data != null && data != undefined) {
                    //var html = "";
                    //for (var i = 0; i < data.length; i++) {
                    //    html += "<tr>";
                    //    html += "<td><input type='checkbox'  onclick='selectAItem(this)' class='chks' mediaId='" + data[i].media_id + "'/></td>"
                    //    html += "<td>" + data[i].media_id + "</td>";
                    //    html += "<td>" + data[i].allTitle + "</td>";
                    //    html += "<td>" + data[i].update_time + "</td>";
                    //    html += "</tr>";
                    //}
                    //$("#dvList").html(html);
                    $("#dvList").empty().html($("#temp1").render(data));
                    PageCountHtml();
                }
                else {
                    $("#dvList").html("没有查询到相关数据！");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                //alert(errorThrown);
            }
        });
    }

    function selectAItem(obj) {
        $('.chks').prop("checked", false);
        $(obj).prop("checked", true);
        selMediaId = $(obj).attr("mediaId");
    }




    //翻页
    function PageCountHtml() {
        pageCount = Math.ceil(totalCount / pageSize);
        if (pageCount == 0) {
            pageCount = 1;
        }
        $("#manage_page").html(PageHtml(pageIndex, pageCount));
        $("#manage_page .manage_page_right").click(function () {
            pageIndex = parseInt($("#txtPageNum").val()) + parseInt($(this).attr("tname"));
            $("#manage_page").html(PageHtml(pageIndex, pageCount));
            gotoPage();
        });
        $("#manage_page .tiaozhuan").click(function () {
            var pageNum = $("#txtPageNum").val();
            try {
                pageIndex = parseInt(pageNum);
            } catch (e) {
                alert("请输入数字");
                return false;
            }

            if (pageNum > 0 && pageNum <= pageCount) {
                $("#manage_page").html(PageHtml(pageIndex, pageCount));
                gotoPage();
            }
            else {
                alert("当前数字超出范围");
                return false;
            }
        });
    }

    function btnSend() {
        if (confirm("群发机会有限，请检查选择分组是否正确？")) {
            if (selMediaId != "") {
                var groupid = $("#groupid").val();
                $.ajax({
                    url: '@Url.Action("QunFaSendToGroup", "Report")',
                    type: 'post',
                    data: { groupid: groupid, mediaId: selMediaId, weixinid: weixinid },
                    success: function (data) {
                        alert(data);
                    }
                });
            } else {
                alert("请选择需要群发的素材！");
            }
        }
    }
</script>
<div class="right">
    <h3>素材发布列表</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <ul class="manage_top_ul">
            </ul>
            <p class="manage_add">
                <span id="spGroupID"></span>
                <a id="btnSend" onclick="btnSend()">群发给该组别</a>
            </p>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_bottom-->
        <div class="manage_bottom">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <th><span>选择</span></th>
                    <th><span>media_Id</span></th>
                    <th><span>标题</span></th>
                    <th><span>日期</span></th>
                </tr>
                <tbody id="dvList"></tbody>
            </table>
            <div class="manage_page" id="manage_page">
            </div>
        </div>
        <!--manage_bottom end-->
    </div>
    <!--manage end-->

</div>
